<template>
	<view class="p-10">


		<view class="bg-white p-20 " style="padding-bottom: 50px">
			<view id="bm_top_height" class="p-b-10  a-c" style="flex-wrap: wrap;display: flex;">

				<view class="banmi_flex">
					<view style="padding: 0 7rpx;"> <button @click="on_add()" type="primary" size="mini"> 新增 </button>
					</view>

				</view>
			</view>
			<uni-table v-if="is_top_height" :top_height="top_height" border stripe @selection-change="selectionData">
				<uni-tr style=" position:sticky;top: 0;z-index: 999;">

					<uni-th align="center" >id</uni-th>

					<uni-th align="center" >名称</uni-th>
					
					<uni-th align="center" >图标</uni-th>

					<uni-th align="center" >排序</uni-th>

					<uni-th align="center"  class="operate_right">操作</uni-th>

				</uni-tr>
				<uni-tr v-for="(vo,index) in list" :key="index">
					<uni-td align="center" >
						{{vo.id}}
					</uni-td>
					<uni-td align="center" >
						{{vo.name}}
					</uni-td>
					<uni-td align="center" >
						 <image :src="vo.img|getImg"   style="width: 80px;height: 80px;" ></image>
					</uni-td>
					<uni-td align="center" >
						{{vo.sort}}
					</uni-td>
					<uni-td class="operate_right" buts="buts">
						<view class="t-c">
							<button @click="on_edit(index)" class="operate_button" type="primary" size="mini">
								编辑
							</button>
						</view>
						<view class="t-c">
							<button @click="on_dels(index)" class="operate_button" type="primary"
								size="mini">删除</button>
						</view>
					</uni-td>
				</uni-tr>
			</uni-table>
			<view class=" p-t-20 bg-white">
				<uni-pagination @change="getPage" show-icon="true" :total="total" current="1"
					style="float: left;margin-bottom: 10px;"></uni-pagination>
			</view>

			<edit ref="component_edit" @confirm="confirm_edit">
			</edit>
			<uni-popup ref="component_dels" type="center">
				<dels :id="id" @confirm="confirm_dels">
				</dels>
			</uni-popup>

		</view>
	</view>
</template>

<script>
	import edit from './edit.vue';
	import dels from './dels.vue';

	export default {
		components: {
			edit,
			dels,
		},
		data() {
			return {
				find: {},

				list: [],
				total: 0,
				page: 1,
				id: 0,
				is_top_height: false,
			}
		},
		onLoad(on) {

			this.init();
		},
		created() {
			let that = this
			setTimeout(function() {
				let element = document.getElementById("bm_top_height");
				that.top_height = element.offsetHeight;
				that.is_top_height = true;
			}, 200);
		},
		methods: {
			//全选 反选
			selectionData(list) {
				 
			},


			on_edit(index) {
				this.id = this.list[index]['id'];
				this.$refs.component_edit.init(this.id)
			},
			confirm_edit() {
				if (this.id == 0) {
					this.page = 1;
				}
				this.init();

			},
			on_dels(index) {
				this.id = this.list[index]['id'];
				this.$refs.component_dels.open()
			},
			confirm_dels() {
				this.init();
				this.$refs.component_dels.close()
			},


			getPage(id) {
				this.page = id.current;
				this.init()
			},
			on_add() {
				this.id = 0;
				this.$refs.component_edit.init(0)
			},
			on_search() {
				this.init();
			},
			on_search_resetting() {
				this.find = {};
				this.page = 1;
				this.init();
			},
			init() {
				var that = this;
				this.find['page'] = this.page
				this.Http.post('banmichaoqiangbizhi/admin/Shoptag/lists',this.find).then(ret => {
					var list = ret.data.list.list;
					this.list = list;
					this.total = ret.data.list.total;
				})
			},
		}
	}
</script>

<style>
	.operate_button {
		width: 70px;
	}

	.operate_right {
		position: sticky;
		right: 0;
		z-index: 100;
		background-color: #fff;
	}
</style>